<template>
  <default-layout>
    <header-back text="档案认证" slot="header"></header-back>
    <div slot="main">
      <div class="con">
        <div class="tit">人脸识别</div>
        <div class="desc">点击开始人脸识别认证</div>
        <div class="img" @click="cert">
          <img src="./1.png" alt="人脸识别">
        </div>
      </div>
      <div class="desc-2">验证身份信息后，可使用更多高级服务</div>
      <mt-button type="primary" size="large" class="btn" @click="cert">立即认证</mt-button>
    </div>
  </default-layout>
</template>
<script>
  import HeaderBack from '../../../components/header-back/header-back.vue'
  import DefaultLayout from '../../../layouts/default-layout/default-layout'
  import {mapGetters} from 'vuex'

  export default {
    components: {DefaultLayout, HeaderBack},
    computed: {
      ...mapGetters([
        'userInfo'
      ])
    },
    data() {
      return {}
    },
    methods: {
      cert() {
        // 人脸识别
        if (window.android) {
          window.android.veriface()
        } else if (window.veriface) {
          window.veriface()
        } else {
          this.$message.alert('当前环境不支持该功能')
        }
        window.verifaceResult = (str) => {
          this.auth(str)
        }
      },
      auth(imageBase64) {
        this.$post('/account/sapi/get/readName/auth/byCardIdAndPhoto', {
          idCard: this.userInfo.aac002,
          imageBase64
        }, loading => { this.$message.loading(loading) }, false).then(res => {
          this.$message.alert(res.message).then(() => {
            this.$router.back()
          })
        }).catch(err => {
          this.$message.alert(err.message || '网络异常')
        })
      }
    }
  }
</script>
<style lang="scss" scoped>
  @import "../../../common/style/variable";
  .con{
    background: #fff;
    margin: .4rem .2rem 0 .2rem;
    padding: .3rem 0;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .desc{
      padding: .15rem 0;
      font-size: .28rem;
      color: #666;
    }
    .tit{
      font-size: .33rem;
      color: $primary;
    }
    .img{
      width: 35%;
      img{
        width: 100%;
      }
    }
  }
  .desc-2{
    padding: .15rem 0;
    font-size: .28rem;
    color: #000;
    text-align: center;
  }
  .btn{
    margin: .5rem 0 0 0;
  }
</style>
